package com.example.smartcity4.ui.metro;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;

import com.bumptech.glide.Glide;
import com.example.smartcity4.MainActivity;
import com.example.smartcity4.R;
import com.example.smartcity4.javaBean.GsonBean;
import com.example.smartcity4.javaBean.MetroDalBean;
import com.example.smartcity4.reteofi.SmartService;

import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;
import retrofit2.Retrofit;
import retrofit2.converter.gson.GsonConverterFactory;

public class MetroCityActivity extends AppCompatActivity {
    private TextView title;
    private ImageView left;
    private ImageView image;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_metro_city);


        title = findViewById(R.id.title);
        left = findViewById(R.id.left);
        image = findViewById(R.id.image);

        title.setText("总览图");

initData();
    }

    private void initData() {
            Retrofit retrofit = new Retrofit.Builder().baseUrl(MainActivity.host)
                    .addConverterFactory(GsonConverterFactory.create())
                    .build();
            SmartService service = retrofit.create(SmartService.class);

            Call<MetroDalBean> call = service.get_city();
            call.enqueue(new Callback<MetroDalBean>() {
                @Override
                public void onResponse(Call<MetroDalBean> call, Response<MetroDalBean> response) {
                    Glide.with(getApplicationContext()).load(MainActivity.host+response.body().data.imgUrl).into(image);
                }

                @Override
                public void onFailure(Call<MetroDalBean> call, Throwable throwable) {
Toast.makeText(getApplicationContext(),"数据获取失败", Toast.LENGTH_SHORT).show();
                }
            });

    }
}